package com.wuyi.tea.controller.common;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
import com.wuyi.tea.domain.dto.UserDTO;
import com.wuyi.tea.domain.pojo.User;
import com.wuyi.tea.domain.vo.R;
import com.wuyi.tea.domain.vo.UserVO;
import com.wuyi.tea.service.UserService;
import com.wuyi.tea.util.LocalStorageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "账户模块")
@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private UserService userService;

    @ApiOperation("获取账户信息")
    @GetMapping("/info")
    public R getAccountInfo(){
        log.info("id为{}的用户获取了账户信息", LocalStorageUtil.get());
        User accountInfo = userService.getById(LocalStorageUtil.get().toString());
        UserVO userVO = BeanUtil.copyProperties(accountInfo, UserVO.class);
        return R.success("获取账户信息成功",userVO);
    }


    @ApiOperation("修改账户信息")
    @PutMapping("/info")
    private R updateAccountInfo(@RequestBody UserDTO userDto){
        log.info("id为{}的用户修改了账户信息,{}",LocalStorageUtil.get(),userDto);
        userService.updateInfo(userDto);
        return R.success();
    }



    @ApiOperation("获取账户余额")
    @GetMapping("/balance")
    private R getAccountBalance(){
        log.info("id为{}的用户获取了账户余额",LocalStorageUtil.get());
        Double accountBalance=userService.getByBalance(Long.valueOf(LocalStorageUtil.get().toString()));
        return R.success(accountBalance);
    }

}
